package wqlbatisplus.batispluswql.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import wqlbatisplus.batispluswql.cv.LoginOb;
import wqlbatisplus.batispluswql.cv.Result;
import wqlbatisplus.batispluswql.entity.User;
import wqlbatisplus.batispluswql.service.UserService;

import java.util.List;

/**
 * @author wql
 * @version 1.0
 * @date 2022/11/19 16:00
 */

@RestController
@RequestMapping("/user")
@Api(tags = "用户后台管理系统")
public class UserController {
    @Autowired
    private UserService userService;
    //登录
    @PostMapping("/login")
    public Result login(@RequestBody LoginOb loginOb){
        return userService.login(loginOb.getUsername(),loginOb.getPassword());
    }
    @GetMapping("/list")
    @ApiOperation(value = "查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", defaultValue = "1", required = true, value = "页码", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", defaultValue = "3", required = true, value = "条数", dataType = "int")
    })
    public Result list(Integer currentPage, Integer pageSize){
        return userService.findByPage(currentPage,pageSize);
    }

    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加")
    public Result add(@RequestBody User user){
        return userService.addUser(user);
    }

    @DeleteMapping("/delete")
    @ResponseBody
    @ApiOperation(value = "删除")
    @ApiImplicitParam(name = "id", defaultValue = "1", required = true, value = "编号", dataType = "int")
    public Result delete(Integer id){
        return userService.deleteById(id);
    }
    @PutMapping("/update")
    @ResponseBody
    @ApiOperation(value = "修改")
    public Result update(@RequestBody User user){
        return userService.update(user);
    }
}
